srcdir =        @srcdir@
top_srcdir =    @top_srcdir@

prefix  =       @prefix@
datadir =       @datadir@

PACKAGE =	@PACKAGE@
LOCDIR =        @LOCDIR@

DESTDIR = 

SOURCES =       @NLS_SOURCES@
POFILES =	@NLS_POFILES@
POXFILES =	@NLS_POXFILES@
MOFILES =	@NLS_MOFILES@

INSTALL =       @INSTALL@
INSTALLDIR =    @INSTALLDIR@
INSTALLLIB =    @INSTALLLIB@
XGETTEXT =	@XGETTEXT@
MSGMERGE =	@MSGMERGE@
MSGFMT =	@MSGFMT@

.SUFFIXES:
.SUFFIXES: .po .mo

all: $(MOFILES)

install: all
	@echo "Installing message catalogues in $(DESTDIR)$(LOCDIR)"
	@for catalog in $(MOFILES); do \
	     lang=`echo $${catalog} | sed -e 's/\.mo//'` ; \
	     msgdir="$(DESTDIR)$(LOCDIR)/$${lang}/LC_MESSAGES"; \
	     echo "Installing language: $${lang}" ; \
	     $(INSTALLDIR) "$${msgdir}"; \
	     $(INSTALLLIB) "$${catalog}" "$${msgdir}/$(PACKAGE).mo"; \
	done

clean:
	rm -f  $(MOFILES) *~


# Merge existing translations and new code
merge: $(POXFILES)

# POTFILES.in lists files containing translatable strings
POTFILES.in: $(SOURCES)
	echo $(SOURCES) | tr ' ' '\n' > $@

# $(PACKAGE).pot is a template file for translations
$(PACKAGE).pot: POTFILES.in
	$(XGETTEXT) --default-domain=$(PACKAGE) --directory=../src \
	--add-comments --keyword=_ --keyword=N_ --files-from=POTFILES.in && \
	test ! -f $(PACKAGE).po || \
	( rm -f ./$(PACKAGE).pot && \
	  mv $(PACKAGE).po ./$(PACKAGE).pot )

# create new translations
%.pox: %.po $(PACKAGE).pot
	$(MSGMERGE) --indent --no-location --output-file $@ $< $(PACKAGE).pot

# convert portable into machine objects
.po.mo:
	$(MSGFMT) -o $@ $<


report.html: *.po Makefile
	@(echo "<h1>National Language Support Status Report</h1>"; \
	  date; echo "<p>"; \
	  for catalog in *.po; do \
	    echo -n "<li>$${catalog}"; \
	    sed -ne's|^.*"Last-Translator[^:]*:\(.*\)<.*$$| by\1<ul>|p' \
                "$${catalog}"; \
		echo -n ' <li>'; \
		LC_ALL=en $(MSGFMT) -o /dev/null "$${catalog}" 2>&1 |\
		sed -e's|, |<li>|g' -e's|\.$$||'; \
		echo '</ul>'; \
	  done ) >$@
	@cat $@

#upload-report: report.html
#	scp report.html massel@icewm.sf.net:icesf/libphp/nls.html

stats:
	for x in *.po ; do echo -ne "$$x:\t" `$(MSGFMT) --statistics $$x` ; done

update: merge
	for x in *.pox ; do cp -af $$x $${x%%pox}po ; done
